#include"process.h"

#define NUM 80
//此时[]只打印79个#
#define STYLE '='
#define STYLE1 '>'

void Process() 
{
    char bar[NUM];
    //因为打印的是一个字符数组的进度条
    //我们先将内存设置为'\0'
    memset(bar, '\0', sizeof(bar));
    const char *lable = "|/-\\";
    int len = strlen(lable);
    int cnt = 0;
    int persent = 0;
    while (cnt < NUM - 1) {
        bar[cnt] = STYLE1;
        persent = (int)((float)(cnt + 1) / (NUM - 1) * 100);
        printf("[%-79s][%-3d%%][%c]\r", bar, persent, lable[cnt % len]);
        //这里要记得回车才能在原地显示
        
        //强制刷新
        fflush(stdout);
        usleep(50000);
        bar[cnt] = STYLE;
        printf("[%-79s][%-3d%%][%c]\r", bar, persent, lable[cnt % len]);
        fflush(stdout);
        cnt++;
        //if (cnt < NUM - 1) {
        //    bar[cnt] = '>';
        //}


        //usleep(10000);
    }
    bar[--cnt] = '=';
    printf("\r[%s]\n", bar);
}
